package com.bltec.emergency.mapper;

import com.bltec.emergency.model.RecordDisaster;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecordDisasterMapper {

    //插入一条disaster记录
    @Insert("insert into record_disaster (disaster_name,disaster_type,occurred_position,issue_time,casualties,href,create_by,create_time,enable) values(#{disasterName},#{disasterType},#{occurredPosition},#{issueTime},#{casualties},#{href},#{createBy},#{createTime},#{enable})")
    boolean insert(RecordDisaster recordDisaster);

    //通过disasterName字段删除disaster记录
    @Delete("delete from record_disaster where disaster_name=#{disasterName}")
    boolean deleteByDisasterName(String disasterName);

    //通过id设置一条记录为不可用
    @Update("update record_disaster set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //id,disasterName,disasterType,occurredPosition,issueTime,casualties,href
    //通过id更新一条记录
    @Update("update record_disaster set disaster_name=#{disasterName},disaster_type=#{disasterType},occurred_position=#{occurredPosition}," +
            "issue_time=#{issueTime},casualties=#{casualties},href=#{href},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateDisasterById(RecordDisaster recordDisaster);

    //查找符合disasterName字段的记录
    @Select("select * from record_disaster where disaster_name =#{disasterName} and enable=1")
    RecordDisaster getDisasterByDisasterName(String disasterName);

    //查找符合disasterName字段的记录的id
    @Select("select id from record_disaster where disaster_name =#{disasterName} and enable=1")
    Long getIdByDisasterName(String disasterName);

    //查找符合id字段的记录
    @Select("select * from record_disaster where id =#{id} and enable=1")
    RecordDisaster getDisasterById(Long id);

    //查找所有记录
    @Select("select * from record_disaster where enable=1")
    List<RecordDisaster> selectAll();

}